import platform
import re


def gen_keyword(title, url):
    keywords = []
    main_category = ''
    type = ''
    genres = [
        "喜剧",
        "动作",
        "爱情",
        "科幻",
        "奇幻",
        "神秘",
        "幻想",
        "恐怖",
        "战争",
        "冒险",
        "惊悚",
        "剧情",
        "传记",
        "历史",
        "纪录"
    ]

    # 分类判断
    if re.findall('/gq/.*', url):
        keywords.append('经典')
        main_category = 'movie'
    elif re.findall('/zydy/.*', url):
        keywords.append('动漫新番')
        main_category = 'tv'
        type = 'cartoon'
    elif re.findall('/jddy/.*', url):
        keywords.append('动画电影')
        main_category = 'movie'
        type = 'cartoon'
    elif re.findall('/dlz/.*', url):
        keywords.append('国剧')
        main_category = 'tv'
    elif re.findall('/rj/.*', url):
        keywords.append('日韩剧')
        main_category = 'tv'
    elif re.findall('/mj/.*', url):
        keywords.append('欧美剧')
        main_category = 'tv'

    # 提取《前面的部分
    promotes = re.findall('(.*?)《', title)
    if promotes:
        pre_title = promotes[0]
        # 匹配genres中的关键词
        for genre in genres:
            if genre in pre_title:
                keywords.append(genre)
        # 如果没有分类，默认为movie
        if not main_category:
            main_category = 'movie'

    return main_category, list(set(keywords)), type


def is_linux():
    system = platform.system()
    return system == "Linux"
